package main

import (
	"fmt"
	"math/rand"
	"sort"
	"time"
)

// 20.编写一个函数实现顺序遍历map中的元素。
func sortMap(student map[string]int) {
	var names []string
	for name := range student {
		names = append(names, name)
	}
	sort.Strings(names)
	for _, name := range names {
		fmt.Printf("%s%d\n", name, student[name])
	}
}
func main() {
	rand.Seed(time.Now().UnixNano()) //初始化随机数种子

	var scoreMap = make(map[string]int, 20)

	for i := 0; i < 20; i++ {
		key := fmt.Sprintf("Map%02d--", i) //生成Map开头的字符串
		value := rand.Intn(20)             //生成0~99的随机整数
		scoreMap[key] = value
	}

	sortMap(scoreMap)

}
